﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;

namespace WebSite.UserSetting
{
    public partial class EditPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region 保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string currentpassword = txtCurrentPassword.Text.Trim();
            string newpassword = txtNewPassword.Text.Trim();

            //判断原密码是否正确
            Users uinfo = new Users();
            uinfo = UserBase.GetCurrentUser();
            if (uinfo == null)
            {
                Tools.AlertAndRedirect("请登录！", "../Login.aspx");
                return;
            }
            else
            {
                string password = uinfo.Password;
                string encurrentpassword = Encrypt.Encode(currentpassword);
                if (encurrentpassword == password)//密码相同
                {
                    uinfo.Password = encurrentpassword;
                    UsersHelper uhelper = new UsersHelper();
                    uhelper.EditUsers(uinfo);
                    Tools.Alert("密码修改成功！");
                    return;
                }
                else//密码不同
                {
                    Tools.Alert("原密码输入不正确！");
                    return;
                }
            }
        }
        #endregion
    }
}